package com.dollar.juc.threadPool;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 1、IO密集、cpu密集、混合型任务三种线程池策略
 * 2、强制给线程命名
 * 3、监控线程池状态
 * 4、线程池优雅关闭
 */

public class ThreadPoolUtils {
    private static final int IO_MAX = 1;

    private static class IOIntenseTargetThreadPoolLazyHolder {
        private static final ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
                IO_MAX, IO_MAX,
                10, TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(10)
        );

        private IOIntenseTargetThreadPoolLazyHolder() {
        }
    }

    public static ThreadPoolExecutor getIoIntenseTargetThreadPool() {
        return IOIntenseTargetThreadPoolLazyHolder.threadPoolExecutor;
    }
}
